package cn.gmph.blog.admin.service.sys.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.sys.dao.helper.LinksProvider;
import cn.gmph.blog.admin.service.sys.entity.LinksDO;

import java.util.List;;

public interface LinksDAO {

    @Results({@Result( column = "link_id",property = "linkId"),@Result( column = "link_url",property = "linkUrl"),@Result( column = "link_name",property = "linkName"),@Result( column = "link_image",property = "linkImage"),@Result( column = "link_target",property = "linkTarget"),@Result( column = "link_description",property = "linkDescription"),@Result( column = "link_visible",property = "linkVisible"),@Result( column = "link_owner",property = "linkOwner"),@Result( column = "link_rating",property = "linkRating"),@Result( column = "link_updated",property = "linkUpdated"),@Result( column = "link_rel",property = "linkRel"),@Result( column = "link_notes",property = "linkNotes"),@Result( column = "link_rss",property = "linkRss") })
    @Select("SELECT * FROM wp_links WHERE id = #{id}")
    public LinksDO getById(@Param("id") int id);

    @Insert("INSERT into wp_links(link_id,link_url,link_name,link_image,link_target,link_description,link_visible,link_owner,link_rating,link_updated,link_rel,link_notes,link_rss) VALUES (#{linkId},#{linkUrl},#{linkName},#{linkImage},#{linkTarget},#{linkDescription},#{linkVisible},#{linkOwner},#{linkRating},#{linkUpdated},#{linkRel},#{linkNotes},#{linkRss})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(LinksDO links);

    @Delete("DELETE FROM wp_links WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = LinksProvider.class, method = "update")
    public int update(@Param("links") LinksDO  links);

    @Results({@Result( column = "link_id",property = "linkId"),@Result( column = "link_url",property = "linkUrl"),@Result( column = "link_name",property = "linkName"),@Result( column = "link_image",property = "linkImage"),@Result( column = "link_target",property = "linkTarget"),@Result( column = "link_description",property = "linkDescription"),@Result( column = "link_visible",property = "linkVisible"),@Result( column = "link_owner",property = "linkOwner"),@Result( column = "link_rating",property = "linkRating"),@Result( column = "link_updated",property = "linkUpdated"),@Result( column = "link_rel",property = "linkRel"),@Result( column = "link_notes",property = "linkNotes"),@Result( column = "link_rss",property = "linkRss") })
    @SelectProvider(type = LinksProvider.class, method = "pageList")
    public List<LinksDO> pageList(@Param("links") LinksDO links, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = LinksProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("links") LinksDO links);

}